<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Parent
 *
 * @author Administrator
 */
class ParentClass {
    private $router;
    protected $upload;
    public function __construct() {
         $this->router=  Loader::load("router");
         $this->upload=  UploadFile::getInstance();
    }
    /**
     * 获得图片的缩略图地址
     * @global type $_G 
     * @param type $picpath  原图地址
     * @param type $style    缩略图大小
     * @return type     缩略图地址
     */
    public function getThumb($picpath,$style){
         global $_G;
         $imagepath="";
         if(isset($_G["upload_image"]["image_path"])){
             $imagepath=$_G["upload_image"]["image_path"];
         }
         
         if(stripos($picpath, $imagepath)!==FALSE){
             $picpath=str_replace($imagepath, "", $picpath);
         }
      
         return $this->upload->getImageUrl($picpath,$style);
     }
    //载入数据库表对象，参数1：表名
     protected function load($table_name){
         return new MysqlDB($table_name);
     }
     //载入逻辑对象,参数1：逻辑对象名称
     protected function uselogic($logicname){
         if($logicname){
             $logicname=  strtolower($logicname);
             $logicname=  ucfirst($logicname);
             $logicname=$logicname."Logic";
             if(class_exists($logicname)){
                 return new $logicname();
             }
         }
         return FALSE;
     }
     
     //做跳转,提示跳转
     protected function showmessage($msg,$type = "error",$url='',$timeout=1000){
         if($url!=''){
         $script="<script>setTimeout(function(){window.location.href='{$url}';},{$timeout});</script>";
         $javascript=$url;
         }else{
         $javascript="javascript:void(0);";
         $script="<script>setTimeout(function(){window.history.go(-1);},{$timeout});</script>"; 
         }
         $html="<style>html,body{overflow: hidden;}</style><meta name='viewport' content='width=device-width, initial-scale=1'><div style='float: left;position:relative;min-height:300px;left:50%;margin:30px -140px;padding:10px 10px;width:260px;box-shadow: rgba(0,0,0,.27) 0 1px 3px,#DCDCDC 0 1px 0,#DDD 0 -1px 0;border-radius: 8px;color:#3c763d;font-size: 15px;font-family: Microsoft yahei;'><p style='color:red;'>{$type}:</p><p style='text-align:center;'>{$msg}</p><p style='position:absolute;bottom:0px;width:100%;text-align:center;left:0px;'><a href='{$javascript}' style='text-decoration: none;color:red;'>点击返回</a></p></div>";
        
         echo $html.$script;
     }
     /**
      * php 直接跳转
      * @param type $url 要跳转的url
      */
     protected function redirect($url){
         header("location: {$url}");
     }
     /**
      * 
      * @return type 获得方法名
      */
     protected function getAction(){
        
         return $this->router->getAction();
     }
     /**
      * 
      * @return type 获得控制器名
      */
      protected function getControll(){
         return $this->router->getControll();
     }
     /**
      * 退出输出json数据
      * @param type $arr 要输出的json数组
      */
     protected function jpExit($arr){
         exit(json_encode($arr));
     }
     public function runThread($arg){
        $base_url=$_SERVER['HTTP_HOST'];
        $fp = fsockopen($base_url, 80, $errno, $errstr);
        fputs($fp, "GET {$arg} / HTTP/1.1\r\nHost: {$base_url}\r\nConnection: Close\r\n\r\n");
        fclose($fp);
    }
}
